package com.xy.biz.base.service.impl;

import com.xy.biz.base.client.EquipmentEventBusClient;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

/**
 * @author Greekn Zhang
 * @date 2021/7/5 10:29
 * @description
 */
@Service
public class EquipmentEventBus implements EquipmentEventBusClient {
    private List<Consumer<List<Long>>> occupyEquipmentList = new CopyOnWriteArrayList<>();
    private List<Consumer<List<Long>>> releaseEquipmentList = new CopyOnWriteArrayList<>();

    public void addOccupyEquipmentHandler(Consumer<List<Long>> handler) {
        occupyEquipmentList.add(handler);
    }

    public void addReleaseEquipmentHandler(Consumer<List<Long>> handler) {
        releaseEquipmentList.add(handler);
    }

    @Override
    public void firerOccupyEquipmentHandler(List<Long> equipmentIdList) {
        occupyEquipmentList.forEach(e -> e.accept(equipmentIdList));
    }

    @Override
    public void firerReleaseEquipmentHandler(List<Long> equipmentIdList) {
        releaseEquipmentList.forEach(e -> e.accept(equipmentIdList));
    }
}
